package com.cykj.user.controller;

import com.cykj.common.dto.ResponseDTO;
import com.cykj.user.service.IUploadFileService;
import com.cykj.user.util.GetFileUtil;
import com.cykj.user.vo.FileResumeVO;
import com.cykj.user.vo.UserVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @BelongsProject: smart_recruit_backend
 * @BelongsPackage: com.cykj.user.controller
 * @Author: 浮行
 * @CreateTime: 2025-08-20 09:07
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/uploadFile")
public class UploadFileController {
    @Autowired
    private IUploadFileService uploadFileService;
    @Autowired
    private GetFileUtil getFileUtil;

    //删除简历
    @GetMapping("/deleteResume")
    @Operation(summary = "删除简历")
    @Parameters({
            @Parameter(name = "resumeId",description = "简历id",required = true,in = ParameterIn.QUERY)
    })
    public ResponseDTO deleteResume(@RequestParam("resumeId") Integer resumeId){
        FileResumeVO fileResumeVO = new FileResumeVO();
        fileResumeVO.setResumeId(resumeId);
        return uploadFileService.delete(fileResumeVO);
    }
    //查询简历数据
    @GetMapping("/selectResume")
    @Operation(summary = "根据用户id查询简历数据")
    @Parameters({
            @Parameter(name = "userId",description = "id",required = true,in = ParameterIn.QUERY)
    })
    public ResponseDTO selectResume(@RequestParam("userId") Integer userId){
        FileResumeVO fileResumeVO = new FileResumeVO();
        fileResumeVO.setUserId(userId);
        return uploadFileService.resumeList(fileResumeVO);

    }

    //附件简历上传
    @PostMapping("/addResume")
    @Operation(summary = "附件简历上传")
    @Parameters({
            @Parameter(name = "userId",description = "用户id",required = true,in = ParameterIn.QUERY),
            @Parameter(name = "fileUrl",description = "简历文件路径",required = true,in = ParameterIn.QUERY)
    })
    public ResponseDTO addResume(@RequestParam("userId") Integer userId,
                                 @RequestParam(value = "fileUrl", required = false) MultipartFile fileUrl){
        String filePath = getFileUtil.filesUpload(fileUrl);
        return uploadFileService.uploadResume(userId,filePath);
    }
    //修改用户头像
    @PostMapping("/updateAvatar")
    @Operation(summary = "修改用户头像")
    @Parameters({
            @Parameter(name = "userId",description = "用户id",required = true,in = ParameterIn.QUERY),
            @Parameter(name = "fileUrl",description = "头像图片路径",required = true,in = ParameterIn.QUERY)
    })
    public ResponseDTO updateAvatar(@RequestParam("userId") Integer userId,
                                    @RequestParam(value = "headIcon", required = false) MultipartFile headIcon){
        String imagePath = getFileUtil.filesUpload(headIcon);

        UserVO userVO = new UserVO(userId,imagePath);

        return uploadFileService.updateHeadIcon(userVO);

    }
}
